package com.mapper;

import com.entity.TArticleStatus;
import com.entity.TArticleStatusExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface TArticleStatusMapper {
    @SelectProvider(type=TArticleStatusSqlProvider.class, method="countByExample")
    int countByExample(TArticleStatusExample example);

    @DeleteProvider(type=TArticleStatusSqlProvider.class, method="deleteByExample")
    int deleteByExample(TArticleStatusExample example);

    @Delete({
        "delete from t_article_status",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into t_article_status (aid, totay_reader_count, ",
        "today_comment_count, today_reply_count, ",
        "create_time)",
        "values (#{aid,jdbcType=VARCHAR}, #{totayReaderCount,jdbcType=INTEGER}, ",
        "#{todayCommentCount,jdbcType=INTEGER}, #{todayReplyCount,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(TArticleStatus record);

    @InsertProvider(type=TArticleStatusSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(TArticleStatus record);

    @SelectProvider(type=TArticleStatusSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
        @Result(column="totay_reader_count", property="totayReaderCount", jdbcType=JdbcType.INTEGER),
        @Result(column="today_comment_count", property="todayCommentCount", jdbcType=JdbcType.INTEGER),
        @Result(column="today_reply_count", property="todayReplyCount", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TArticleStatus> selectByExample(TArticleStatusExample example);

    @Select({
        "select",
        "id, aid, totay_reader_count, today_comment_count, today_reply_count, create_time",
        "from t_article_status",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
        @Result(column="totay_reader_count", property="totayReaderCount", jdbcType=JdbcType.INTEGER),
        @Result(column="today_comment_count", property="todayCommentCount", jdbcType=JdbcType.INTEGER),
        @Result(column="today_reply_count", property="todayReplyCount", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    TArticleStatus selectByPrimaryKey(Integer id);

    @UpdateProvider(type=TArticleStatusSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TArticleStatus record, @Param("example") TArticleStatusExample example);

    @UpdateProvider(type=TArticleStatusSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") TArticleStatus record, @Param("example") TArticleStatusExample example);

    @UpdateProvider(type=TArticleStatusSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TArticleStatus record);

    @Update({
        "update t_article_status",
        "set aid = #{aid,jdbcType=VARCHAR},",
          "totay_reader_count = #{totayReaderCount,jdbcType=INTEGER},",
          "today_comment_count = #{todayCommentCount,jdbcType=INTEGER},",
          "today_reply_count = #{todayReplyCount,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TArticleStatus record);

    @Select({
            "select",
            "id, aid, totay_reader_count, today_comment_count, today_reply_count, create_time",
            "from t_article_status",
            "where aid = #{aid,jdbcType=VARCHAR} order by create_time desc limit 1"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
            @Result(column="totay_reader_count", property="totayReaderCount", jdbcType=JdbcType.INTEGER),
            @Result(column="today_comment_count", property="todayCommentCount", jdbcType=JdbcType.INTEGER),
            @Result(column="today_reply_count", property="todayReplyCount", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    TArticleStatus selectLatestByAid(String aid);

}